package com.song.oscsong.adapter;

import java.util.List;
import java.util.zip.Inflater;

import com.song.oscsong.R;
import com.song.oscsong.bean.News;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class NewsAdapter extends BaseAdapter {
	
	private List<News> datas;
	private ViewHolder holder;

	public NewsAdapter(List<News> datas) {
		super();
		this.datas = datas;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return datas.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return datas.get(position);
	}



	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
	
		ViewHolder holder = null;
		if(convertView ==null)
		{
			holder = new ViewHolder();
			convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_cell, null);
			holder.title = (TextView) convertView.findViewById(R.id.tv_title);
			holder.description = (TextView) convertView.findViewById(R.id.tv_description);
			holder.source = (TextView) convertView.findViewById(R.id.tv_source);
			holder.time = (TextView) convertView.findViewById(R.id.tv_time);
			holder.comment_count = (TextView) convertView.findViewById(R.id.tv_comment_count);
			holder.tip = (ImageView) convertView.findViewById(R.id.tv_tip);
			convertView.setTag(holder);
		}else{
			
			holder = (ViewHolder) convertView.getTag();
		}
		
		News news = datas.get(position);
		holder.title.setText( news.getTitle());
		holder.time.setText( news.getPubDate());
		holder.source.setText( news.getSoftwareName());
		holder.description.setText( news.getBody());
		holder.comment_count.setText( news.getCommentCount()+"");
		return convertView;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	
	static class ViewHolder{
		TextView title;
		TextView description;
		TextView source;
		TextView time;
		TextView comment_count;
		ImageView tip;	
		
	}
}
